package edu.ncu.interceptor;

import edu.ncu.entity.User;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class AuthorityInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        System.out.println("进入了权限控制拦截器");
        User user = (User)request.getSession().getAttribute("user");
        if(user!=null && user.getAccount().equals("admin"))
            return true;
        else
        {
            //相当于：http://localhost:8080/makefriend + "/error"
            response.sendRedirect(request.getContextPath()+"/error");
            return false;
        }
    }
}
